﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Expect.Core.Errors;
//using NUnit.Framework.SyntaxHelpers;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Expect.Core.IO;
//using MakeSure = NUnit.Framework.Assert;

namespace Expect.Core.Test
{
    using Expect.Core.BaseClasses;

    [TestClass]
    public class BasisTest
    {
        [TestMethod]
        public void DefaultNameProvider_PascalCase()
        {
            DefaultNameProvider nameP = new DefaultNameProvider();
            string name = nameP.ElementName(new string[] { "test%", "élément hôtel", "name€" });
            Assert.AreEqual("TestPercentElementHotelNameEuros", name);
            //MakeSure.That(name, Is.EqualTo("TestPercentElementHotelNameEuros"));
        }

        [TestMethod]
        public void DefaultNameProvider_Conform()
        {
            DefaultNameProvider nameP = new DefaultNameProvider();
            DefaultNameProvider_Conform(nameP, "élément hôtel", "elementhotel");
            DefaultNameProvider_Conform(nameP, "élément hôtel()", "elementhotel");
        }

        [TestMethod]
        public void DefaultNameProvider_ElementName()
        {
            DefaultNameProvider nameP = new DefaultNameProvider();
            DefaultNameProvider_ElementName(nameP, "L'Automne et l'été", "LAutomneEtLEte");
            DefaultNameProvider_ElementName(nameP, "Youpla-boom", "YouplaBoom");
        }

        private void DefaultNameProvider_ElementName(DefaultNameProvider nameP, string actual, string expected)
        {
            string conformed = nameP.ElementName(actual);
            Assert.AreEqual(expected, conformed);
            //MakeSure.That(conformed, Is.EqualTo(expected));
        }

        private void DefaultNameProvider_Conform(DefaultNameProvider nameP, string actual, string expected)
        {            
            string conformed = nameP.ConformString(actual);
            Assert.AreEqual(expected, conformed);
            //MakeSure.That(conformed, Is.EqualTo(expected));
        }

        [TestMethod]
        //[ExpectedException(typeof(UnresolvedFixtureError))]
        public void Classe_Non_Renseignee()
        {
            SpecificationDefinition test = new SpecificationDefinition();

            var definition = new FixtureDefinition(test)
                .WithRow("col1", "col2", "col3", "sum()")
                .WithRow(   "1",    "2",    "3",    "6");
            
            test.Add(definition);

            DefaultSpecificationExecution runner = new DefaultSpecificationExecution();
            runner.Run(this, test);

            Assert.IsFalse(test.IsSuccessful);
            Assert.IsTrue(test.HasError<ElementNotFoundError>(e => e.Kind == ElementKind.Fixture));
        }

        [TestMethod]
        public void Fixture_Class_Resolution()
        {
            SpecificationDefinition test = new SpecificationDefinition();

            var definition = new FixtureDefinition(test)
                .WithRow("Column fixture impl")
                .WithRow("col1", "col2", "col3", "sum()")
                .WithRow("1", "2", "3", "6");

            test.Add(definition);

            DefaultSpecificationExecution runner = new DefaultSpecificationExecution();
            runner.Run(this, test);
        }

        //// TODO : test running modes
        //// TODO : tests type conversion
    }
}
